package com.pig4cloud.pig.demo.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.security.annotation.Inner;
import com.pig4cloud.pig.demo.Service.OrderService;
import com.pig4cloud.pig.demo.Util.TokenUtils;
import com.pig4cloud.pig.demo.feign.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 订单
 * Created by caoxuel on 2020/10/17 17:21
 * @author caoxuel
 */
@RestController
@CrossOrigin
@RequestMapping("/article/order")
@Inner
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 分页查询订单
     * @param page
     * @param limit
     * @return
     */
    @Inner(value = false)
    @GetMapping("/{page}/{limit}")
    public R queryOrderList(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            HttpServletRequest request) {
        Page<OrderVO> page1 = new Page<>(page, limit);
        Long id = TokenUtils.getId(request);
        return R.ok(orderService.queryOrderList(page1, id));
    }

    /**
     * 通过id删除订单
     * @param id id
     * @return R
     */
    @DeleteMapping("/{id}" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(orderService.removeById(id));
    }
}
